﻿

function beforeDrag(treeId, treeNodes) {

    return false;
}
var setting = {
    edit: {
        enable: true
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        beforeRemove: function (treeId, treeNode) {
            if (treeNode.name.indexOf('2') > -1) {
                return false;
            }
        },
        beforeRename: function (treeId, treeNode, newName, isCancel) {


            if (newName.indexOf('2') > -1) {
                return false
            }
            //console.log(e)
        }
    }
};
function setEdit() {
    var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
        remove = $("#remove").attr("checked"),
        rename = $("#rename").attr("checked"),
        removeTitle = $.trim($("#removeTitle").get(0).value),
        renameTitle = $.trim($("#renameTitle").get(0).value);
    zTree.setting.edit.showRemoveBtn = remove;
    zTree.setting.edit.showRenameBtn = rename;
    zTree.setting.edit.removeTitle = removeTitle;
    zTree.setting.edit.renameTitle = renameTitle;
    showCode(['setting.edit.showRemoveBtn = ' + remove, 'setting.edit.showRenameBtn = ' + rename,
    'setting.edit.removeTitle = "' + removeTitle + '"', 'setting.edit.renameTitle = "' + renameTitle + '"'
    ]);
}
function NodeGenerator(data) {
    data =
    [
    { "strategyId": "1", "name": "\u56DB\u5468", "code": "sdfdsfdsfdsfdsf", "isLast": true },
    { "strategyId": "2", "name": "\u56DB\u54682", "code": "sdfdsfdsfdsfdsf", "isLast": false }
        ]
    var zNodes=[]
    for (var i = 0; i < data.length; i++) {
        zNodes.push({
            id: data[i].strategyId,
            pId: 0,
            name: data[i].name,
            open: data[i].isLast
        });  
        zNodes.push({
            id: 2,
            pId: data[i].strategyId,
            name: "main.py"
        });
        zNodes.push({
            id: 3,
            pId: data[i].strategyId,
            name: "schema1"
        });  
        zNodes.push({
            id: 4,
            pId: data[i].strategyId,
            name: "schema2"
        });  
    }
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    //setEdit();
    $("#remove").bind("change", setEdit);
    $("#rename").bind("change", setEdit);
    $("#removeTitle").bind("propertychange", setEdit)
        .bind("input", setEdit);
    $("#renameTitle").bind("propertychange", setEdit)
        .bind("input", setEdit);
}
function LoadStrategy() {
    $.ajax({
        type: 'get',
        url: '/RPC/StrategyList',
        data: null,
        success: function (data) {
            //console.log(data)
            var setting4solutions = {
                edit: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                },
                callback: {
                    beforeRemove: function (treeId, treeNode) {
                        //请求删除node
                        if (treeNode.name.indexOf('2') > -1) {
                            return false;
                        }


                    },
                    beforeRename: function (treeId, treeNode, newName, isCancel) {

                        //请求修改node
                        if (newName.indexOf('2') > -1) {
                            return false
                        }
                        //console.log(e)
                    }
                }
            };
        }
    });
}